package taller2.controller.modes.supervisor;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.Iterator;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import taller2.interfaces.Connection;
import taller2.interfaces.Graph;
import taller2.utils.Constants;
import taller2.view.menus.supervisor.FordFulkersonSupervisorMenu;

public class FordFulkersonSupervisorButtonListener implements ActionListener {
	private FordFulkersonSupervisorMenu menu;
	private Graph graph,solution;
	
	public FordFulkersonSupervisorButtonListener(Graph graph,Graph solution, FordFulkersonSupervisorMenu fordFulkersonSupervisorMenu) {
		this.menu = fordFulkersonSupervisorMenu;
		this.graph = graph;		
		this.solution = solution;

	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		menu.unselectButtons();

		
		Collection<Connection> connectionsOrig = graph.getAllConnections().values();
		Collection<Connection> connectionsSol = solution.getAllConnections().values();
		
		Iterator<Connection> it1 = connectionsOrig.iterator();
		Iterator<Connection> it2 = connectionsSol.iterator();

		while(it1.hasNext() && it2.hasNext()){
			Connection toTest = it1.next();
			Connection sol = it2.next();
			
			boolean c1 = (toTest.getFlux() != sol.getFlux());
			boolean c2 = (toTest.getCapacity() != sol.getCapacity());

			if(c1 || c2){
				JFrame frame = new JFrame();
				JOptionPane.showMessageDialog(frame,Constants.errorMsg);	
				return;
			}
				
		}
		
		JFrame frame = new JFrame();
		JOptionPane.showMessageDialog(frame,Constants.okMsg);	
	}

}